package CSDN;

import java.util.function.ObjIntConsumer;

/**
 * Created with IntelliJ IDEA.
 * Description: 并发执行
 * User: 王圆豪
 * Date: 2025-05-06
 * Time: 10:53
 */
public class Test10 {
    static int count = 0;
    public static void main(String[] args) throws InterruptedException {
        Object locker = new Object();
        Thread t1 = new Thread(()->{
            for (int i = 0; i < 50000; i++) {
                synchronized (locker) {
                    synchronized (locker) {
                        count++;
                    }
                }
            }
        });
        Thread t2 = new Thread(()->{
            for (int i = 0; i < 50000; i++) {
                synchronized (locker) {
                    count++;
                }
            }
        });

        t1.start();
        t2.start();

//        t1.start();
//        t1.join();
//        t2.start();
//        t2.join();

        //保证线程都执行完
        Thread.sleep(1000);

        System.out.println(count);
    }
}
